package com.qezhhnjy.cloud.ribbon.service;

import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;

import javax.annotation.Resource;

/**
 * @author qezhhnjy
 * @date 2020/7/29-23:44
 */
@Service
public class HiService {

    @Resource
    private RestTemplate restTemplate;

    @HystrixCommand(fallbackMethod = "hiError")
    public String hi(String name) {
        String http = "http://eureka-client/hi?name=" + name;
        return restTemplate.getForObject(http, String.class);
    }

    public String hiError(String name) {
        return "hi " + name + " sorry error!!!";
    }
}
